package cn.bitkit.tools.common;

/**
 * @author changbo
 */
public class ByteUtil {

	public static byte[] xor(byte[] bytes1, byte[] bytes2){
		int minLen = Math.min(bytes1.length, bytes2.length);
		byte[] res = new byte[minLen];
		for(int i = 0; i < minLen; i++){
			res[i] = (byte)(bytes1[i] ^ bytes2[i]);
		}
		return res;
	}
	
	public static byte[] subBytes(byte[] bytes, int offset, int length) {
		byte[] sub = new byte[length];
		length = (bytes.length < offset+length) ? bytes.length-offset : length;
		System.arraycopy(bytes, offset, sub, 0, length);
		return sub;
	}

}
